package com.cn.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: chenyuncong
 * @Date: 2019/12/16 11:12
 */
@RestController
public class IndexController {

    @RequestMapping(value = {"/","index"})
    public Map<String,String> index() throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();
        return new HashMap<String,String>(){{
            this.put("name","admin");
            this.put("sex","男");
            this.put("email","admin@qq.com");
            this.put("address",address.getHostAddress());
        }};
    }

    @RequestMapping("test1")
    public String test1() {
        return "Hello World";
    }

    @RequestMapping("test2")
    public String test2() {
        if (true) {
            throw new RuntimeException("a exception occured");
        }
        return "Hello World2";
    }

    @RequestMapping("test3")
    public String test3() throws InterruptedException {
        Thread.sleep(10000);
        return "Hello World3";
    }

}
